<template>
  <div class="page-department">
    <div class="component-mainHeader">
      <div class="top">
        <div class="topleft">
          <p>
            <span class="iconfont" style="color:#1abc9a;margin-right:3px;">&#xe607;</span>申请列表
          </p>
        </div>
        <div class="topright">
          <el-button type="info" @click="$router.go(0)">
            <span style="font-weight:700;margin-right:5px;" class="iconfont">&#xe662;</span>刷新
          </el-button>
        </div>
      </div>
    </div>
    <div class="component-searchHeader">
      <div class="search-header">
        <div class="left-title">
          <p class="left-text">
            <span class="iconfont" style="font-weight:700;margin-right:3px;">&#xe63d;</span>筛选查询
          </p>
          <div class="right">
            <button @click="finRes">查询</button>
          </div>
        </div>
      </div>
    </div>
    <div class="component-search-box">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="输入搜索：">
          <el-input clearable v-model="formInline.num" placeholder="采购编号"></el-input>
        </el-form-item>
        <!--<el-form-item label="材料类型：">-->
          <!--<el-select v-model="formInline.type" placeholder="全部">-->
            <!--<el-option label="？" value="main"></el-option>-->
            <!--<el-option label="？" value="sup"></el-option>-->
          <!--</el-select>-->
        <!--</el-form-item>-->
        <el-form-item label="申请部门：">
          <el-select v-model="formInline.org" clearable placeholder="全部">
            <el-option  v-for="(item,index) in applyList" :key="index" :label="item.orgName" :value="item.orgId"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </div>
    <!-- 表格 -->
    <div class="component-listHeader">
      <div class="search-header">
        <div class="left-title">
          <p class="left-text">
            <span class="iconfont">&#xe61e;</span>
            申请列表
          </p>
          <div class="right"></div>
        </div>
      </div>
    </div>

    <div class="table">
      <el-table ref="multipleTable" :data="info" tooltip-effect="dark" style border>
        <el-table-column label="采购编号" align="center" prop="buyNo"></el-table-column>
        <el-table-column label="时间" align="center">
          <template slot-scope="scope">
            {{scope.row.applyDate | dateFilter}}
          </template>
        </el-table-column>
        <el-table-column label="申请部门" align="center" prop="applyOrgName"></el-table-column>
        <el-table-column label="申请人" align="center" prop="applyUser"></el-table-column>
        <el-table-column label="采购总价" align="center" prop="buyMoney"></el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              @click="detailsBtn(scope.row.buyId)"
              type="text"
              size="small"
              class="red"
              style="color:#1abc9a;"
            >查看详情</el-button>
            <el-button type="text" size="small" class="red" style="color:#1abc9a;" v-if="scope.row.flowStatus == 20" @click="accpet(scope.row)">同意</el-button>
            <el-button type="text" size="small" class="red" style="color:#1abc9a;" v-if="scope.row.flowStatus == 20" @click="disAccpet(scope.row)">驳回</el-button>
            <el-button type="text" size="small" class="red" style="color:#1abc9a;" v-if="scope.row.flowStatus == 21">已同意</el-button>
            <el-button type="text" size="small" class="red" style="color:#1abc9a;" v-if="scope.row.flowStatus == 29">已驳回</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <div class="component-paging" v-if="info.length > 0">
      <div class="table-bottom">
        <div class="bottom-left"></div>
        <div class="paging">
          <div class="paging-left">
            <p>
              共
              <span>{{Math.ceil(total/pageSize)}}</span> 页/
              <span>{{total}}</span> 条数据
            </p>
          </div>
          <el-pagination
            background
            @size-change="SizeChange($event,dataInit,currentPage,pageSize)"
            @current-change="CurrentChange($event,dataInit,currentPage,pageSize)"
            :current-page="currentPage"
            :page-sizes="[10, 20, 30]"
            :page-size="pageSize"
            layout="sizes, prev, pager, next, jumper"
            :total="total"
          ></el-pagination>
        </div>
      </div>
    </div>
    <!-- <div class="component-model">
      <el-dialog :title="modelTitle" :visible.sync="dialogVisible" width="800px">
        <div>
          <div class="table">
            <el-table ref="multipleTable" :data="modelInfo" tooltip-effect="dark" style border>
              <el-table-column label="序号" align="center" width="55" prop="num"></el-table-column>
              <el-table-column label="材料名称" align="center" prop="name"></el-table-column>
              <el-table-column label="型号" align="center" width="100" prop="type"></el-table-column>
              <el-table-column label="单据数量" align="center" width="90" prop="paper"></el-table-column>
              <el-table-column label="实领数量" align="center" width="92" prop="real"></el-table-column>
              <el-table-column label="单价" align="center" width="92" prop="price"></el-table-column>
              <el-table-column label="对内库存" align="center" width="92" prop="inside"></el-table-column>
              <el-table-column label="对外库存" align="center" width="92" prop="outside"></el-table-column>
            </el-table>
          </div>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false;addPerson">确定</el-button>
        </span>
      </el-dialog>
    </div> -->
  </div>
</template>

<script>
export default {
  data() {
    return {
      info: [],
      formInline: {
        num: "",
        type:"",
        org:""
      },
      applyList:[],
      // 数据总条数
      total: 0,
      // 每页显示数据的条数
      pageSize: 10,
      // 当前显示的页面页码
      currentPage: 1,
    //   dialogVisible: false
    };
  },
  mounted() {
      this.dataInit();
      this.departMent();
  },
  methods: {
    //点击查询
    finRes(){
      this.currentPage = 1;
      this.dataInit();
    },
    //初始化函数
    dataInit(){
      let that = this;
      let suCb = function(res){
        that.info = res.data.data;
        that.total = res.data.rowCount;
        console.log(res.data)
      }
      let erCb = function(res){
        console.log(res)
      }
      let postData = {
        info: that.formInline.num,
        applyUser: that.formInline.org,
        pageSize: that.pageSize,
        pageCurrent: that.currentPage,
        buySource:"1" //1-项目部采购，2-施工队采购
      }
      let palyParam = {
        url: "/api/web/proBuyApply/selectWorkApply",
        methods:'post',
        data: postData,
        success: suCb,
        error: erCb,
      }
      that.$https(palyParam)
    },
    //查看详情
    detailsBtn(val) {
      this.$router.push({ name: "seDetail",params:{id:val}});
    },
    //同意驳回
    flowStatus(val,n1,n){
      let that = this;
      let suCb = function(res){
        if(n == 0){
          that.$message({
            message: '已同意',
            type: 'success'
          });
        }else{
          that.$message({
            message: '已驳回',
            type: 'success'
          });
        }
        that.dataInit();
      }
      let erCb = function(res){
        console.log(res)
      }
      let postData = {
        proBuyApply:{
          buyId:val.buyId,
          flowStatus:n1
        }
      }
      let palyParam = {
        url: "/api/web/proBuyApply/updateBuyApplyState",
        methods:'post',
        data: postData,
        success: suCb,
        error: erCb,
      }
      that.$https(palyParam)
    },
    //申请列表
    departMent(){
      let that = this;
      let suCb = function(res){
        that.applyList = res.data.data
        console.log(res.data)
      }
      let erCb = function(res){
        console.log(res)
      }
      let postData = {
      }
      let palyParam = {
        url: "/api/web/sysOrg/selectOrgName",
        methods:'post',
        data: postData,
        success: suCb,
        error: erCb,
      }
      that.$https(palyParam)
    },
    //同意
    accpet(val){
      this.flowStatus(val,21,0)
    },
    //驳回
    disAccpet(val){
      this.flowStatus(val,29,1)
    }
  }
};
</script>

<style scoped>
.component-searchHeader .search-header {
  width: 1100px;
  box-sizing: border-box;
  border: 1px solid rgba(228, 228, 228, 1);
  background-color: rgba(255, 255, 255, 1);
  margin: 20px auto 0;
}

.component-searchHeader .search-header .left-title {
  display: flex;
  justify-content: space-between;
  width: 100%;
  background-color: rgba(243, 243, 243, 1);
  height: 45px;
  box-sizing: border-box;
}

.component-searchHeader .search-header .left-title .left-text {
  width: 20%;
  color: #666;
  line-height: 45px;
  font-family: "微软雅黑";
  font-weight: 400;
  font-size: 12px;
  text-align: left;
  margin: 0 0 0 30px;
}

.component-searchHeader .right {
  width: 70%;
  display: flex;
  justify-content: flex-end;
  margin-right: 30px;
}

.component-search-box {
  width: 1100px;
  height: 60px;
  box-sizing: border-box;
  background-color: #fff;
  border: 1px solid #e4e4e4;
  border-top: none;
  margin: 0 auto;
  text-align: left;
  padding-left: 30px;
  line-height: 60px;
}

.component-search-box .el-input__inner {
  height: 35px;
  display: inline-block;
}

.component-listHeader .search-header {
  width: 1100px;
  box-sizing: border-box;
  border: 1px solid rgba(228, 228, 228, 1);
  background-color: rgba(255, 255, 255, 1);
  margin: 20px auto 0;
  border-bottom: 0;
}

.component-listHeader .search-header .left-title {
  display: flex;
  justify-content: space-between;
  width: 100%;
  background-color: rgba(243, 243, 243, 1);
  height: 45px;
  box-sizing: border-box;
}

.component-listHeader .search-header .left-title .left-text {
  width: 20%;
  color: #666;
  font-size: 14px;
  line-height: 45px;
  font-weight: 700;
  text-align: left;
  margin: 0 0 0 30px;
}

.component-listHeader .search-header .right {
  width: 70%;
  display: flex;
  justify-content: flex-end;
  margin-right: 10px;
}

.component-listHeader .search-header .right button {
  padding: 0 15px;
  height: 30px;
  width: 80px;
  margin: 6px 5px;
  line-height: 30px;
  font-size: 14px;
  color: #666;
  background-color: #fff;
  border: 1px solid #ccc;
}

.component-listHeader .search-header .right button:hover {
  background-color: #f3f3f3;
}

.table {
  width: 1100px;
  margin: 0 auto;
}

.el-table .cell a {
  color: #1abc9a;
  text-decoration: none;
  cursor: pointer;
}

/* .component-model .table {
  width: 750px;
  margin: 0 auto;
} */
</style>
